package com.ayoka.mvp;

import com.ayoka.R;
import com.ayoka.base.BasePresenter;
import com.ayoka.base.IBaseView;
import com.ayoka.bean.BaseResponse;
import com.ayoka.bean.CouponBean;
import com.ayoka.http.API;
import com.ayoka.http.OkHttpListener;
import com.ayoka.mvp.PurchaseRecordMVP.PurchaseRecordModel.PurchaseRecordBean;
import com.jcp.baselibrary.utils.UIUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by gabriel on 2017/3/5.
 */

public interface PurchaseRecordMVP {

    interface PurchaseRecordModel {

        class PurchaseRecordBean {
            public int ID;
            public String TradeCode;
            public double total_fee;
            public String Descp;
            public String CreateDate;
        }
    }

    interface IPurchaseRecordView extends IBaseView {

        void configPurchaseRecordListData(List<PurchaseRecordBean> listData);
    }

    class PurchaseRecordPresenter extends BasePresenter<IPurchaseRecordView> {

        public void getPurchaseRecordListData(boolean isShowWaitDialog) {
            if (isShowWaitDialog) {
                mViewRef.get().showWaitDialog(UIUtils.getString(R.string.loading));
            }
            API.getPurchaseRecordListData(this, new OkHttpListener<BaseResponse<List<PurchaseRecordBean>>>() {
                @Override
                public void onSuccess(BaseResponse<List<PurchaseRecordBean>> response) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().configPurchaseRecordListData(response.data);
                }

                @Override
                public void onFailure(int errorCode, String errorMessage) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().showToast(errorMessage);
                }
            });
        }

    }

}
